﻿using DefPack.Common;
using SaveSation.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SaveSation.Common
{
    public static class Extenssions
    {
        public static void Error(this Exception ex)
        {
            string exception = ex.GetType().FullName;
            Log.E($"[{exception}]Message:{ex.Message}\n.StackTrace:{ex.StackTrace}");
            if (ex.InnerException != null)
                Log.E($"[InnerException]Message:{ex.InnerException.Message}\n.StackTrace:{ex.InnerException.StackTrace}\n.Source:{ex.InnerException.Source}");
        }
        public static int GetIndex(this List<GroupEntity> groups, ArchiveEntity archive)
        {
            if (archive.GroupID.IsNullOrEmpty()) return StartForm._defaultGroup.Index;
            foreach (var group in groups)
            {
                if (group.UUID == archive.GroupID) return group.Index;
            }
            return StartForm._defaultGroup.Index;
        }
        /// <summary>
        /// 检查字符串数组中的字符串是否在被查找的字符串中有匹配值
        /// </summary>
        /// <param name="str"></param>
        /// <param name="array"></param>
        /// <returns></returns>
        public static bool HasString(this string str, params string[] array)
        {
            if (array.Length == 0) return false;
            foreach (var ex in array)
            {
                if (!string.IsNullOrEmpty(ex) && str.IndexOf(ex, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    return true;
                }
            }
            return false;
        }
        public static string ExpandEnvironmentVariables(this string path)
        {
            return Environment.ExpandEnvironmentVariables(path);
        }
    }
}
